﻿using System.Windows.Media;

namespace AutoRevit.Ribbon.Ribbon.Mapper;

/// <summary>
/// PushButton控件映射器
/// </summary>
public class PushButtonMapper : ControlItemMapper
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="text"></param>
    public PushButtonMapper(string name, string text) : base(name)
    {
        Text = text;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    public PushButtonMapper(string name) : this(name, $" {name} ")
    {
    }

    /// <summary>
    /// 
    /// </summary>
    public string AvailabilityClassName { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public string Text { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public ImageSource Image { get; set; } = null!;

    /// <summary>
    /// 
    /// </summary>
    public ImageSource LargeImage { get; set; } = null!;

    /// <summary>
    /// 实际已生成的控件
    /// </summary>
    public PushButton? Control { get; internal set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public PushButtonData GetData()
    {
        var data = new PushButtonData(Name, Text, AssemblyName, ClassName)
        {
            AvailabilityClassName = AvailabilityClassName,
            ToolTipImage = ToolTipImage,
            LargeImage = LargeImage,
            Image = Image,
            ToolTip = ToolTip,
            LongDescription = LongDescription,
        };

        data.SetContextualHelp(GetContextualHelp());

        return data;
    }
}

/// <summary>
/// PushButton控件映射器
/// </summary>
/// <typeparam name="TExternalCommand"></typeparam>
public class PushButtonMapper<TExternalCommand> : PushButtonMapper where TExternalCommand : IExternalCommand
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="text"></param>
    public PushButtonMapper(string name, string text) : base(name, text)
    {
        var type = typeof(TExternalCommand);
        AssemblyName = type.Assembly.Location;
        ClassName = type.FullName!;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    public PushButtonMapper(string name) : this(name, $" {name} ")
    {
    }
}

/// <summary>
/// PushButton控件映射器
/// </summary>
/// <typeparam name="TExternalCommand"></typeparam>
/// <typeparam name="TIExternalCommandAvailability"></typeparam>
public class PushButtonMapper<TExternalCommand, TIExternalCommandAvailability> : PushButtonMapper<TExternalCommand> 
    where TExternalCommand : IExternalCommand 
    where TIExternalCommandAvailability : IExternalCommandAvailability
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    /// <param name="text"></param>
    public PushButtonMapper(string name, string text) : base(name, text)
    {
        var type = typeof(TIExternalCommandAvailability);
        AvailabilityClassName = type.FullName!;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="name"></param>
    public PushButtonMapper(string name) : this(name, $" {name} ")
    {
    }
}